package com.surfilter.modules.user.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.surfilter.modules.user.model.RoleModel;
import com.surfilter.platform.base.dao.DaoBase;

@Repository(value="user_roleDao")
public class RoleDao extends DaoBase{

	@Resource(name = "surfilterSqlMapClient")
	private SqlMapClient sqlMapClient;
	
	@Override
	public void initSqlMapClient() {
		this.setSqlMapClient(sqlMapClient);
	}

	public List<RoleModel> getUserRoles(int userId) {
		return this.getListByObject("getUserRoles", userId);
	}
	public List<RoleModel> getNotUserRoles(Integer userId){
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("userId", userId);
		return this.getListByObject("getNotUserRoles", param);
	}
	public void delAllUserRoles(int userId){
		this.deleteObject("delAllUserRoles", userId);
	}
	public void addAllUserRoles(int userId,List<Integer> roleIds,int updateUser,Date updateTime) {
		List<Map<String,Object>> params = new ArrayList<Map<String,Object>>();
		for(Integer roleId : roleIds){
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("userId", userId);
			param.put("roleId", roleId);
			param.put("createTime", new Date());
//			param.put("updateUser", updateUser);
//			param.put("updateTime", updateTime);
			params.add(param);
		}
		this.addBatch("addAllUserRoles", params);
	}
}
